package ru.tulupov.collectionsbenchmark.model;

public class Car implements Comparable<Car> {

	private String name;
	private int width;
	private int height;

	public Car(String name, int width, int height) {
		setName(name);
		setWidth(width);
		setHeight(height);
	}

	public int getHeight() {
		return height;
	}

	public String getName() {
		return name;
	}

	public int getWidth() {
		return width;
	}

	public void setHeight(int height) {
		if (height < 0) {
			throw new IllegalArgumentException();
		}
		this.height = height;
	}

	public void setName(String name) {
		if (name == null) {
			throw new IllegalArgumentException();
		}
		this.name = name;
	}

	public void setWidth(int width) {
		if (width < 0) {
			throw new IllegalArgumentException();
		}
		this.width = width;
	}

	@Override
	public boolean equals(Object obj) {
		if (obj == null) {
			return false;
		}

		if (obj == this) {
			return true;
		}

		if (obj.getClass() == this.getClass()) {
			Car car = (Car) obj;

			return name.equals(car.name) && (width == car.width)
					&& (height == car.height);
		}

		return false;
	}

	@Override
	public int hashCode() {
		return 17 * name.hashCode() + 31 * width + 47 * height;
	}

	@Override
	public int compareTo(Car car) {
		return width * height - car.width * car.height;
	}

}
